package sldm;

import java.lang.reflect.Constructor;

public class sl7 {
    public static void main(String[] args) {
        try {
            Class clz = Class.forName("entry.Person");
            Constructor cl= clz.getDeclaredConstructor();
            Object obj = cl.newInstance();
            System.out.println(obj);

            //获取单参构造
            Constructor c2 = clz.getDeclaredConstructor(String.class);
            c2.setAccessible(true);
            obj = c2.newInstance("New Person");
            System.out.println(obj);

            //获取person的三参构造
            Constructor c3 = clz.getDeclaredConstructor(String.class,
                                String.class,String.class);
            c3.setAccessible(true);
            obj = c3.newInstance("New Person","beijing","Hello!");
            System.out.println(obj);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
